package xust;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

class Solution {
     List<List<Integer>> res = new ArrayList<>();
     LinkedList<Integer> l = new LinkedList<>();
     public List<List<Integer>> combine(int n, int k) {

         backTracing( n,k,1);
         return res;
     }
     public  void backTracing( int n, int k, int start){
         //结束条件
         if(l.size() == k){
             res.add(new ArrayList<>(l));
             return;
         }
         for(int i = start; i <= n-(k - l.size()) + 1 ; i++){
             l.add(i);
             backTracing( n,k,i+1);
           l.removeLast();
         }
     }

     public static void main(String[] args) {
         Solution solution = new Solution();
         Scanner scanner = new Scanner(System.in);
         System.out.println("输入n：");
         int n = scanner.nextInt();
         System.out.println("输入k");
         int k = scanner.nextInt();
         List<List<Integer>> res = solution.combine(n, k);
         for(List<Integer> list : res){
             System.out.println(list);
         }
         scanner.close();
     }

}